package com.twu.biblioteca;

import java.util.ArrayList;

public class Option {

    public static Option USER_LOGIN = new Option(1, "Login");
    public static Option USER_LOGOUT = new Option(1, "Logout");
    public static Option LIST_ALL = new Option(2, "List all");
    public static Option RESERVE_BOOK = new Option(3, "Reserve book");
    public static Option MEMBERSHIP_INFO = new Option(4, "Membership info");
    public static Option EXIT = new Option(0, "Exit");

    private Integer id;

    private String name;

    public Option(int id, String name) {
        this.id = id;
        this.name = name;
    }

    public Option() {
        //void constructor
    }

    public static Option createFrom(Integer id) {
        Option option = new Option(id, null);

        return option;
    }

    public static ArrayList<Option> getAllOptions() {
        ArrayList<Option> allOptions = new ArrayList<Option>();
        allOptions.add((USER_LOGOUT));
        allOptions.add(Option.USER_LOGIN);
        allOptions.add(Option.LIST_ALL);
        allOptions.add(Option.RESERVE_BOOK);
        allOptions.add(Option.MEMBERSHIP_INFO);
        allOptions.add(Option.EXIT);

        return allOptions;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Option option = (Option) o;

        if (!id.equals(option.id)) return false;

        return true;
    }

    public boolean identical(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Option option = (Option) o;

        if (!id.equals(option.id) || !name.equals(option.name)) return false;

        return true;
    }

    @Override
    public int hashCode() {
        return id.hashCode();
    }

}
